package io.github.hadyang.leetcode.offer;

import org.junit.Test;

/** @author haoyang.shi */
public class Add {

  @Test
  public void test() {
    System.out.println(Add(5, 17));
    System.out.println(Add(111, 899));
  }

  public int Add(int num1, int num2) {
    int sum, carry;
    do {
      sum = num1 ^ num2;
      carry = (num1 & num2) << 1;

      num1 = sum;
      num2 = carry;
    } while (num2 != 0);

    return sum;
  }
}
